package entity;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 爆炸效果类
 */
public class Explosion {
    private int x;
    private int y;
    private List<Image> frames; // 动画帧
    private int currentFrame; // 当前帧索引
    private int frameDelay; // 帧延迟
    private int frameCount; // 帧计数器
    private boolean finished; // 是否播放完毕
    
    public Explosion(int x, int y, List<Image> frames) {
        this.x = x;
        this.y = y;
        this.frames = frames;
        this.currentFrame = 0;
        this.frameDelay = 5; // 每5帧切换一次图片
        this.frameCount = 0;
        this.finished = false;
    }
    
    /**
     * 更新爆炸动画
     */
    public void update() {
        if (finished) return;
        
        frameCount++;
        if (frameCount >= frameDelay) {
            frameCount = 0;
            currentFrame++;
            if (currentFrame >= frames.size()) {
                finished = true;
                currentFrame = frames.size() - 1;
            }
        }
    }
    
    /**
     * 获取当前帧图片
     * @return 当前帧图片
     */
    public Image getCurrentImage() {
        if (frames.isEmpty()) return null;
        return frames.get(currentFrame);
    }
    
    public int getX() {
        return x;
    }
    
    public int getY() {
        return y;
    }
    
    public boolean isFinished() {
        return finished;
    }
}